﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameFramework;
using GameFramework.Procedure;
using UnityGameFramework.Runtime;
using GameFramework.Event;
using GameFramework.DataTable;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;

public class Demo5_ProcedureLaunch : ProcedureBase
{
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);
        EventComponent Event = GameEntry.GetComponent<EventComponent>();
        DataTableComponent DataTable = GameEntry.GetComponent<DataTableComponent>();
        Event.Subscribe(UnityGameFramework.Runtime.LoadDataTableSuccessEventArgs.EventId, OnLoadDataTableSuccess);
        DataTable.LoadDataTable<DRRoomInfo>("RoomInfo", "Assets/GameMain/DataTables/RoomInfo.txt");
    }

    private void OnLoadDataTableSuccess(object sender, GameEventArgs e)
    {
        UnityGameFramework.Runtime.LoadDataTableSuccessEventArgs ne = e as UnityGameFramework.Runtime.LoadDataTableSuccessEventArgs;
        Log.Info("Load data table '{0}' success.", ne.DataTableName);
        Log.Warning("数据表加载后没数据！！！！");

        DataTableComponent DataTable = GameEntry.GetComponent<DataTableComponent>();
        IDataTable<DRRoomInfo> dtRoomInfo = DataTable.GetDataTable<DRRoomInfo>();
        DRRoomInfo lineInfo = dtRoomInfo.GetDataRow(1);
        if (lineInfo != null)
        {
            Log.Info("Id:" + lineInfo.Id + " roomType:" + " Score:" + lineInfo.AssetName);
        }
    }

    // Use this for initialization
    private void Start()
    {

    }

    // Update is called once per frame
    private void Update()
    {

    }
}
